﻿using Core.Configuration.Config;
using Core.Quartz;

namespace IconYuan.Api.Services
{
    /// <summary>
    /// 定时任务
    /// </summary>
    public class QuartzServices
    {
        /// <summary>
        /// 初始化定时任务
        /// </summary>
        public static void Start(IServiceCollection servies)
        {
            var quartz = new QuartzPro();
            quartz.Start().GetAwaiter().GetResult();

            //清理VIP过期任务(间隔2小时)
            quartz.CreateJob<UrlJob>(new UrlJobInfo()
            {
                JobName = "ResetVip",
                Seconds = 60 * 60 * 2,
                Url = $"{GlobalConfig.ApiDomain}system/resetVip"
            }).GetAwaiter().GetResult();

            //清理无效订单任务(间隔12小时)
            quartz.CreateJob<UrlJob>(new UrlJobInfo()
            {
                JobName = "ClearOrder",
                Seconds = 60 * 60 * 12,
                Url = $"{GlobalConfig.ApiDomain}system/clearOrder"
            }).GetAwaiter().GetResult();

            //清理过期优惠券任务(间隔12小时)
            quartz.CreateJob<UrlJob>(new UrlJobInfo()
            {
                JobName = "ClearCoupon",
                Seconds = 60 * 60 * 12,
                Url = $"{GlobalConfig.ApiDomain}system/clearCoupon"
            }).GetAwaiter().GetResult();

            servies.AddSingleton(quartz);
        }
    }
}